$(function () {
	var send_ele = document.getElementById("loginjp");
	var usr_ipt = document.getElementById("uname");
	var pwd_ipt = document.getElementById("password");
	var countjp=0;
	$(".login-tab li").click(function () {
		var index = $(this).index();
		$(this).addClass("current").siblings().removeClass("current");
		$(".mc").eq(index).show().siblings('.mc').hide();
	});
	$("#uname").blur(function () {
		if ($(this).val().length != 0) {
			$(".login_uname label").addClass("yi");
		}
	});
	$("#password").blur(function () {
		if ($(this).val().length != 0) {
			$(".login_password label").addClass("yi");
		}
	});
	$(".over").click(function () {
		if ($("#uname").val().length == 0) {
			alert("请输入用户名");
		}
		else if ($("#password").val().length == 0) {
			alert("请输入密码");
		}
		else {
			var time;
			// console.log(countjp)
			if(countjp==2 || time){
				alert("密码错误三次，30秒不能登录");
				
				console.log(time)
				 time = 30;
				(function() {
					
					// var p = document.getElementsById("time");
					var set = setInterval(function() {
						time--;
						// console.log(time)
						// p.innerHTML = time;
						if(time === 0) {
							// p.innerHTML = "";
							time=undefined;
							countjp=0;
							clearInterval(set);
							return;
						}
					}, 1000);
				})()




			}else{
			// var d = new Date();
            // d.setDate( d.getDate() + 1 );
            // document.cookie = "username="+usr_ipt.value+" ;expires="+ d;
			sendRegisterMsg();
			}
			// alert("登录成功!");
			// $("form").attr("action","index.html");
		}
	});


	function sendRegisterMsg() {
		var xhr = new XMLHttpRequest();
		var url = "http://localhost:81/jd/xposed/dist/assets/php/loginpage.php";
		url += "?username=" + usr_ipt.value + "&password=" + pwd_ipt.value;
		xhr.open("GET", url);
		xhr.send();
		xhr.onreadystatechange = function () {
			if (xhr.readyState === 4 && xhr.status === 200) {
				console.log(xhr.responseText);
				setReisterState(xhr.responseText);
			}
		}
	}
	function setReisterState(res) {
		res = JSON.parse(res);
		if (res.type === "success") {
			var d = new Date();
            d.setDate( d.getDate() + 1 );
            document.cookie = "username="+usr_ipt.value+" ;expires="+ d;
			alert("恭喜登录成功");
			self.location = 'http://localhost:82/index.html';
		} else {
			countjp++;
			alert("密码错误");
		}
	}




});
